package com.rwind.dynamic.common;


/**
 * API 网关接口消息返回格式
 * @author user
 *
 * @param <E>
 */
public class ApiMessageDto<E> {

  private String success;
  private String code;
  private String title;
  private String msg;

  private E data;

  public static <E> ApiMessageDto<E> getSuccess(E data) {
    ApiMessageDto<E> msg = new ApiMessageDto<E>();
    msg.setSuccess("true"); //当success为true时,API网关设置hd.code为1
    msg.setMsg("操作成功");
    msg.setCode("1");//当success为false时,API网关取此字段值设置到hd.code
    msg.setData(data);
    return msg;
  }

  public static <E> ApiMessageDto<E> getFail(E data, String code,String title, String message) {
    ApiMessageDto<E> msg = new ApiMessageDto<E>();
    msg.setSuccess("false");
    msg.setMsg(message);
    msg.setData(data);
    msg.setCode(code);
    msg.setTitle(title);
    return msg;
  }

  public static <E> ApiMessageDto<E> getFail(  String code , String message) {
	    ApiMessageDto<E> msg = new ApiMessageDto<E>();
	    msg.setSuccess("false");
	    msg.setMsg(message);
	    msg.setData(null);
	    msg.setCode(code);
	    msg.setTitle("");
	    return msg;
	  }



  /**
   * 获取返回结果消息
   *
   * @return the msg
   */
  public String getMsg() {
    return msg;
  }

  /**
   * 设置返回结果消息
   *
   * @param msg the msg
   */
  public void setMsg(String msg) {
    this.msg = msg;
  }

  /**
   * 获取返回结果数据
   *
   * @return the data
   */
  public E getData() {
    return data;
  }

  /**
   * 设置返回结果数据
   *
   * @param data the data
   */
  public void setData(E data) {
    this.data = data;
  }

  public static <E> ApiMessageDto<E> initSuccess(E body) {
    ApiMessageDto<E> responseDto = new ApiMessageDto<E>();
    responseDto.setSuccess("true");
//    responseDto.setCode("1");
    responseDto.setMsg("操作成功");
    responseDto.setData(body);
    return responseDto;
  }




  public static <E> ApiMessageDto<E> initFail(E body, String message) {
    ApiMessageDto<E> responseDto = new ApiMessageDto<E>();
    responseDto.setSuccess("false");
    responseDto.setCode("0");
    responseDto.setMsg(message);
    responseDto.setData(body);
    return responseDto;
  }

  public static <E> ApiMessageDto<E> initFail(E body, String code, String message) {
    ApiMessageDto<E> responseDto = new ApiMessageDto<E>();
    responseDto.setSuccess("false");
    responseDto.setCode(code);
    responseDto.setMsg(message);
    responseDto.setData(body);
    return responseDto;
  }

 
  

  public String getSuccess() {
    return success;
  }

  public void setSuccess(String success) {
    this.success = success;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }



}
